package com.lineage.server.datatables.sql;

import com.lineage.DatabaseFactory;
import com.lineage.server.datatables.storage.OtherUserBuyStorage;
import com.lineage.server.utils.SQLUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class OtherUserBuyTable implements OtherUserBuyStorage {
  private static final Log _log = LogFactory.getLog(OtherUserBuyTable.class);
  
  public void add(String itemname, int itemobjid, int itemadena, long itemcount, int pcobjid, String pcname, int srcpcobjid, String srcpcname) {
    Connection co = null;
    PreparedStatement ps = null;
    try {
      co = DatabaseFactory.get().getConnection();
      ps = co.prepareStatement(
          "INSERT INTO `character_角色_收购` SET `itemname`=?,`itemobjid`=?,`itemadena`=?,`itemcount`=?,`pcobjid`=?,`pcname`=?,`srcpcobjid`=?,`srcpcname`=?,`datetime`=SYSDATE()");
      int i = 0;
      ps.setString(++i, itemname);
      ps.setInt(++i, itemobjid);
      ps.setInt(++i, itemadena);
      ps.setLong(++i, itemcount);
      ps.setInt(++i, pcobjid);
      ps.setString(++i, String.valueOf(String.valueOf(pcname)) + "(买家)");
      ps.setInt(++i, srcpcobjid);
      ps.setString(++i, String.valueOf(String.valueOf(srcpcname)) + "(卖家-商店)");
      ps.execute();
    } catch (Exception e) {
      SqlError.isError(_log, e.getLocalizedMessage(), e);
    } finally {
      SQLUtil.close(ps);
      SQLUtil.close(co);
    } 
  }
}
